package com.chart.chart.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.chart.chart.domian.ChartConfigsAndViewsVo;

import com.chart.chart.domian.ChartConfigsUser;
import com.chart.chart.domian.req.UListReq;
import com.chart.chart.domian.vo.ChartConfigsUserVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * 用户表 数据层
 *
 * @author ruoyi
 */
@Mapper
public interface ChartConfigsUserMapper extends BaseMapper<ChartConfigsUser> {

    List<ChartConfigsUserVo> getListWithOutValue(ChartConfigsUserVo chartConfigsUserVo);

    List<ChartConfigsAndViewsVo> getChartsAndViews(ChartConfigsUser configsUser);

    List<ChartConfigsAndViewsVo> getChartsAndViewsBathByFileIds(@Param("ids") List<Long> ids);

    boolean scatterChartfigsUser(@Param("collect") List<ChartConfigsUser> collect);

    List<ChartConfigsAndViewsVo> getChartsAndViewsBatch(ChartConfigsAndViewsVo chartConfigsAndViewsVo);

    List<ChartConfigsAndViewsVo> getInfoByName(ChartConfigsAndViewsVo chartConfigsAndViewsVo);

    List<ChartConfigsAndViewsVo> getFiles(ChartConfigsAndViewsVo chartConfigsAndViewsVo);

    boolean updateConfigTop(ChartConfigsUser chartConfigsUser);

    /**
     * 根据用户Id 文件名称 文件类型筛选
     *
     * @param userId
     * @param chartName
     * @param chartType
     * @return
     */

    List<ChartConfigsUser> getUsersExcludingChartValue(
            @Param("userId") Long userId,
            @Param("chartName") String chartName,
            @Param("chartType") String chartType,
            @Param("subjectId") Long subjectId,
            @Param("configId") Long configId,
            @Param("sortOrder") Long sortOrder
    );

    /**
     * 更新热度字段
     *
     * @param id
     * @return
     */
    int updateHotById(@Param("id") Long id);


    // ChartConfigsUserMapper.java

    ChartConfigsUser getOneByChartName(@Param("chartName") String chartName, @Param("userId") Long userId);

    @Update("UPDATE chart_configs_user SET redis_key = #{redisKey} WHERE id = #{id}")
    void updateRedisKey(@Param("id") Long id, @Param("redisKey") String redisKey);

    List<ChartConfigsAndViewsVo> getFiles1(ChartConfigsAndViewsVo chartConfigsAndViewsVo);

    List<ChartConfigsAndViewsVo> getChartsAndViewsBatch1(ChartConfigsAndViewsVo chartConfigsAndViewsVo);

    List<ChartConfigsAndViewsVo> getInfoByName1(ChartConfigsAndViewsVo chartConfigsAndViewsVo);


    List<ChartConfigsUser> queryList(Long configId);

    @Select("SELECT COUNT(*) from chart_configs_user where  user_id = #{userId} ")
    Long queryChartCountById(Long userId);


    List<ChartConfigsUser> queryPhotosByUserId(@Param("userId") Long userId);

    List<ChartConfigsUserVo> querychartConfigCount(UListReq req);


    List<ChartConfigsUser> selectConfigsByName(@Param("name") String name, @Param("userId") Long userId);

    List<ChartConfigsUser> selectAllFilesInFolder(Long folderId, Long userId);



    @Select("SELECT version from chart_configs_user where file_id=#{fileId}")
    Integer selectVersionByFileId(@Param("fileId") Long fileId);


    @Update("UPDATE chart_configs_user SET parent_id = #{targetParentId}, version = version + 1 WHERE file_id = #{fileId} AND user_id = #{userId} AND version = #{version}")
    int moveFile(
            @Param("fileId") Long fileId,
            @Param("targetParentId") Long targetParentId,
            @Param("userId") Long userId,
            @Param("version") Integer version
    );
//
//    int moveFile(Long fileId, Long targetParentId, Long userId, Integer version);
}
